package com.ytjj.qmyx.admin.controller.imController;

import com.ytjj.common.api.CommonResult;
import com.ytjj.common.exception.ApiException;
import com.ytjj.qmyx.admin.annotation.OperLog;
import com.ytjj.qmyx.admin.constants.SysLogConstants;
import com.ytjj.qmyx.admin.eunm.im.ImRepositoryEnums;
import com.ytjj.qmyx.admin.model.ImKeyDescribe;
import com.ytjj.qmyx.admin.model.request.ImKeyDescribeReq;
import com.ytjj.qmyx.admin.service.imService.ImKeyDescribeService;
import com.ytjj.qmyx.admin.utils.EmptyUtil;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 
 * 关键描述
 */
@RestController
@AllArgsConstructor
@RequestMapping("/keyDescribe")
public class ImKeyDescribeController {

    private ImKeyDescribeService imKeyDescribeService;

    public CommonResult Describe(ImKeyDescribe imKeyDescribe){
        if(EmptyUtil.isEmpty(imKeyDescribe.getShortcut())){
            throw new ApiException(ImRepositoryEnums.KEY_QUICK_IS_NULL.getMessage());
        }
        if(EmptyUtil.isEmpty(imKeyDescribe.getReply())){
            throw new ApiException(ImRepositoryEnums.KEY_REPLY_IS_NULL.getMessage());
        }
        return CommonResult.success();
    }

    @PostMapping("/describeList")
    @OperLog(operModule = "关键描述", operDesc = "关键描述列表", operType = SysLogConstants.OPERATION_SELECT)
    public CommonResult describeList(@RequestBody ImKeyDescribeReq imKeyDescribeReq) {
        if(EmptyUtil.isEmpty(imKeyDescribeReq.getClassifyId())||imKeyDescribeReq.getClassifyId()==0){
            return CommonResult.failed(ImRepositoryEnums.KEY_CLASSIFY_IS_NULL.getMessage());
        }
        return CommonResult.success(imKeyDescribeService.describeList(imKeyDescribeReq));
    }

    @PostMapping(value = "/insertDescribe")
    @OperLog(operModule = "关键描述", operDesc = "新增关键描述", operType = SysLogConstants.OPERATION_ADD)
    public CommonResult insertDescribe(@RequestBody ImKeyDescribe imKeyDescribe){
        Describe(imKeyDescribe);
        if(EmptyUtil.isEmpty(imKeyDescribe.getClassifyId())||imKeyDescribe.getClassifyId()==0){
            throw new ApiException(ImRepositoryEnums.KEY_CLASSIFY_IS_NULL.getMessage());
        }
        return CommonResult.success(imKeyDescribeService.insertDescribe(imKeyDescribe));
    }

    @GetMapping(value = "/deleteDescribe")
    @OperLog(operModule = "关键描述", operDesc = "移除关键描述", operType = SysLogConstants.OPERATION_UPDATE)
    public CommonResult deleteDescribe(Integer id){
        if(EmptyUtil.isEmpty(id)){
            throw new ApiException(ImRepositoryEnums.KEY_DESCRIBE_IS_NULL.getMessage());
        }
        return CommonResult.success(imKeyDescribeService.deleteDescribe(id));
    }

    @PostMapping(value = "/updateDescribe")
    @OperLog(operModule = "关键描述", operDesc = "修改关键描述", operType = SysLogConstants.OPERATION_UPDATE)
    public CommonResult updateDescribe(@RequestBody ImKeyDescribe imKeyDescribe){
        Describe(imKeyDescribe);
        if(imKeyDescribe.getId()==0){
            throw new ApiException(ImRepositoryEnums.KEY_DESCRIBE_IS_NULL.getMessage());
        }
        return CommonResult.success(imKeyDescribeService.updateDescribe(imKeyDescribe));
    }

    @GetMapping(value = "/selectDescribe")
    @OperLog(operModule = "关键描述", operDesc = "按关键ID查询关键描述信息", operType = SysLogConstants.OPERATION_SELECT)
    public CommonResult selectDescribe(Integer id){
        if(EmptyUtil.isEmpty(id)){
            throw new ApiException(ImRepositoryEnums.KEY_DESCRIBE_IS_NULL.getMessage());
        }
        return CommonResult.success(imKeyDescribeService.selectDescribe(id));
    }

    @GetMapping("/selectKey")
    @OperLog(operModule = "常用词", operDesc = "常用词列表", operType = SysLogConstants.OPERATION_SELECT)
    public CommonResult selectKey(String shortcut) {
        return CommonResult.success(imKeyDescribeService.selectKey(shortcut));
    }
}
